AmCheckForm0 = Ext.extend(
		Ext.Window, 
		{
	// 头部工具栏
	topbar : null,
	// 条件搜索Panel
	searchPanel : null,
	// 数据展示Panel
	gridPanel : null,
	// GridPanel的数据Store
	store : null,
	width : 1200,
	height : 520,
	// 构造函数
	constructor : function(_cfg) {
		Ext.applyIf(this, _cfg);
		// 初始化组件
		this.initUIComponents();
		// 调用父类构造
		AmCheckForm0.superclass.constructor.call(this, {
					id : 'AmCheckForm0',
					title : '电表明细审核',
					width : 1000,
					region : 'center',
					layout : 'border',
					modal : true,
					plain : true,
					items : [this.searchPanel, this.gridPanel]
				});
	},// end of constructor
	// 初始化组件
	initUIComponents : function() {
		// 初始化搜索条件Panel
		this.searchPanel = new Ext.FormPanel({
			id : 'AmCheckForm00',
			height : 100,
			region : 'north',
			frame : false,
			border : false,
			padding : '10',
			layout : 'column',
			title : '',
			labelWidth : 60,
			layoutConfig : {
				padding : '5',
				align : 'middle'
			},
			defaults : {
				columnWidth : 0.33,
				layout : 'form',
				border : false,
				style : 'padding-left:10px;',
				defaults : {
					xtype : 'textfield',
					width : 130
				}
			},
			items : [{
				items : [{
					fieldLabel : '计划名称',
					name : 'Q_planName_S_EQ',
					width : 200,
					value : this.planName,
					readOnly: true,
					style:'color:#666666'
				}, {
					fieldLabel : '电表编号',
					id : 'pdaAmMeterCheck.amId',
					name : 'Q_amId_S_LK'
				},{
					fieldLabel : '房',
					width : 220,
					hiddenName : 'aparmentId_S_LK',
					xtype : 'combo',
					id : 'pdaAmMeterCheck.houseID',
					valueField : 'houseId',
					displayField : 'houseName',
					mode : 'local',
					editable : false,
					triggerAction : 'all',
					store : new Ext.data.SimpleStore({
								url : __ctxPath+ '/pdaweb/showHouseWaterMeterPlan.do?buildingId=',
								fields : ['houseId','houseName']
							}),
					listeners : {
						scope : this,
						select : function(cbo,record, index) {
						}
					}
				
				
				}]
	}, {
		items : [{
			        fieldLabel : '抄表年月',
			        name : 'Q_month_S_EQ',
			        value : this.lastEditBy,
					readOnly: true,
					style:'color:#666666'
					
				},{
					fieldLabel : '区',
					hiddenName : 'districtId_S_LK',
					xtype : 'combo',
					id : 'pdaAmMeterCheck.districtID',
					valueField : 'districtId',
					displayField : 'districtName',
					mode : 'local',
					editable : false,
					triggerAction : 'all',
					store : new Ext.data.SimpleStore({
								url : __ctxPath
										+ '/pdaweb/showDistrictAmPlan.do',
								autoLoad : true,
								fields : ['districtId','districtName']
							}),
					listeners : {
						scope : this,
						select : function(cbo,record, index) {
							var b = Ext.getCmp('pdaAmMeterCheck.buildingID');
							var h = Ext.getCmp('pdaAmMeterCheck.houseID');
							b.setValue('');
							b.store.loadData([]);
							h.setValue('');
							h.store.loadData([]);
							chooseDistrictId = cbo.getValue();
							Ext.Ajax.request({
								url : __ctxPath+ '/pdaweb/showBuildingAmPlan.do?districtId='
										+ chooseDistrictId,
								method : 'post',
								success : function(response,option) {
									b.store.loadData(eval("("+ response.responseText
													+ ")"));
								}
							});
						}
					}
				},{
					xtype : 'button',
					text : '查询',
					region : 'center',
					width : 60,
					iconCls : 'search',
					style : 'margin-center:10px',
					scope : this,
					handler : function(){
						var searchPanel = Ext.getCmp('AmCheckForm00');
						var gridPanel = Ext.getCmp('AmCheckForm0Grid');
						if (searchPanel.getForm().isValid()) {
							$search({
								searchPanel : searchPanel,
								gridPanel : gridPanel
							});
						}
					}
				}]
	},{
		items : [{
					fieldLabel : '抄表人',
					name : 'Q_executor_S_EQ',
					value : this.executor,
					readOnly: true,
					style:'color:#666666'					
				},{
					fieldLabel : '栋',
					hiddenName : 'buildingId_S_LK',
					xtype : 'combo',
					id : 'pdaAmMeterCheck.buildingID',
					valueField : 'buildingId',
					displayField : 'buildingtName',
					mode : 'local',
					editable : false,
					triggerAction : 'all',
					store : new Ext.data.SimpleStore({
								url : __ctxPath+ '/pdaweb/showBuildingAmPlan.do?districtId=',
								//autoLoad : true,
								fields : ['buildingId','buildingtName']
							}),
					listeners : {
						scope : this,
						select : function(cbo,record, index) {
							var h = Ext.getCmp('pdaAmMeterCheck.houseID');
							h.setValue('');
							h.store.loadData([]);
							chooseBulidingId = cbo.getValue();
							Ext.Ajax.request({
								url : __ctxPath+ '/pdaweb/showHouseWaterMeterPlan.do?buildingId='
										+ chooseBulidingId,
								method : 'post',
								success : function(response,option) {
									h.store.loadData(eval("("+ response.responseText+ ")"));
									}
							});
						}
					}
				
				},{
					style : 'margin-top:4px;',
					width : 60,
					xtype : 'button',
					text : '重置',
					iconCls : 'btn-reset',
					handler : function() {
						Ext.getCmp('pdaAmMeterCheck.amId').setValue('');
						Ext.getCmp('pdaAmMeterCheck.districtID').setValue('');
						Ext.getCmp('pdaAmMeterCheck.buildingID').setValue('');
						Ext.getCmp('pdaAmMeterCheck.houseID').setValue('');
						//Ext.getCmp('AmCheckForm00').getForm().reset();
					}
				}]
		
	}, {
		items : [{
					xtype : 'hidden',
					name : 'Q_status_S_EQ',
					value : '1'
				}]
	},{
		items : [{
			xtype:'hidden',
			name : 'Q_planId_S_EQ',
			value: this.planId
		}]
	}]
		});// end of the searchPanel
	
		this.store = new Ext.data.JsonStore({
					url : __ctxPath+ '/pdaweb/checkDetailSearchPdaAmMeterList.do',
					root : 'result',
					totalProperty : 'totalCounts',
					id : 'id',
					fields : [{
						name : 'id',
						type : 'int'
					},'status', 'amId', 'lastDegree', 'degree', 'fixedUsage', 'usage',
								'pdaAmMeter.districtId','pdaAmMeter.buildingId','pdaAmMeter.aparmentId',
								'recorderId', 'month','remark','createddt'],
					remoteSort : true
				});
			
		this.store.baseParams = {
				Q_planId_S_EQ : this.planId,
				Q_month_S_EQ :this.lastEditBy,
				Q_amId_S_LK : "",
				Q_status_S_EQ:'1',
				districtId_S_LK : "",
				buildingId_S_LK : "",
				aparmentId_S_LK : "",
				Q_amId_S_LK :""	,
				Q_planName_S_EQ : this.planName
		};
		
		this.store.load({
			params : {
				start : 0,
				limit : 12				
			}
		});
		
		var sm = new Ext.grid.CheckboxSelectionModel({
            handleMouseDown:Ext.emptyFn,
            listeners:{'beforerowselect': function(s,i,k,r ) {
                      return r.get("status")!='2';
                }
            },
            renderer : function(v,c,r){
	            if(r.get("status")=='2'){
	                return "<div style='padding:3px 0 0 3px;'><input type='checkbox' disabled /></div>";
	            }else{
	                return "<div class=\"x-grid3-row-checker\">&#160;</div>";
	            }
            }            
        });
		
		var cm = new Ext.grid.ColumnModel({
			columns : [sm, new Ext.grid.RowNumberer(), 
			           {
						header : '抄表人',
						width : 60,
						dataIndex : 'recorderId'
					},{
						header : '电表编号',
						width : 120,
						dataIndex : 'amId'
					},{
						header : '区号',
						width : 60,
						dataIndex : 'pdaAmMeter.districtId'
					},{
						header : '栋号',
						width : 100,
						dataIndex : 'pdaAmMeter.buildingId'
					},{
						header : '房号',
						width : 150,
						dataIndex : 'pdaAmMeter.aparmentId'
					},{
						header : '本月读数',
						width : 60,
						dataIndex : 'degree'
					},{
						header : '上月读数',
						width : 60,
						dataIndex : 'lastDegree', // lastdegree
						renderer : function(val) {
							return val == -1 ? "" : val;
						}
					},{
						header : '本月用量',
						width : 60,
						dataIndex : 'usage'
					},{
						header : '修正量',
						width : 50,
						dataIndex : 'fixedUsage'
					},{
						header : '备注',
						width : 150,
						dataIndex : 'remark'
					},{
						header : '操作',
						width : 50,
						dataIndex : 'id',
						sortable : false,
						renderer : function(value, metadata, record, rowIndex,
								colIndex) {
							var d = record.data;
							var str = '';
							str += '&nbsp;<button title="修正上月读数" value="" class="btn-edit" '
								+ 'onclick="AmCheckForm0.fix('
								+ record.data.id
								+ ');">&nbsp</button>';
							return str;
						}
					}],
			defaults : {
				sortable : true,
				menuDisabled : false
			}
		});// end of the cm

		this.topbar = new Ext.Toolbar({
					id : 'AmCheckForm0FootBar',
					height : 25,
					bodyStyle : 'text-align:left',
					items : [{
						xtype : 'button',
						text : '审核',
						region : 'center',
						width : 60,
						iconCls : 'btn-add',
						style : 'margin-center:10px',
						scope : this,
						handler : function() {
							var grid = Ext.getCmp("AmCheckForm0Grid");
							var selectRecords = grid.getSelectionModel().getSelections();
							if (selectRecords.length == 0) {
								Ext.ux.Toast.msg("信息", "请选择记录！");
								return;
							}
							var warnIds = '';
							var waitIds = '';
							for (var i = 0; i < selectRecords.length; i++) {
								var st = selectRecords[i].data.status;
								if ('WAIT' == AmCheckForm0.getST(st)) {
									waitIds += selectRecords[i].data.id + ',';
								} else if ('WARN' == AmCheckForm0.getST(st)) {
									warnIds += selectRecords[i].data.id + ',';
								}
							}
							if (warnIds != '') {
								Ext.Msg.confirm('提示',
										'选择中包含黄颜色警示记录,你确定要审核通过吗？', function(
												btn, text) {
											if (btn == 'yes') {
												AmCheckForm0.check(waitIds
														+ warnIds);
											} else {
												return false;
											}
										});
							} else {
								if (waitIds != '') {
									AmCheckForm0.check(waitIds)
								}
							}
						}
					}]
					
				});

		this.gridPanel = new Ext.grid.GridPanel({
					id : 'AmCheckForm0Grid',
					region : 'center',
					store : this.store,
					trackMouseOver : true,
					disableSelection : false,
					loadMask : true,
					autoHeight : true,
					tbar : this.topbar,
					cm : cm,
					sm : sm,
					viewConfig : {
						showPreview : false,
						getRowClass : function(record, rowIndex, rowParams,store) {// 异常状态
							var st = record.data.status;
							if ('ERROR' == AmCheckForm0.getST(st)) {
								return 'x-grid-record-error';
							} else if ('WARN' == AmCheckForm0.getST(st)) {
								return 'x-grid-record-warning';
							} else {
								return '';
							}
						}
					},
					bbar : new Ext.PagingToolbar({
								pageSize : 12,
								store : this.store,
								displayInfo : true,
								displayMsg : '当前显示从{0}至{1}， 共{2}条记录',
								emptyMsg : "当前没有记录"
							})
				});			
	}
});

AmCheckForm0.fix = function(id) {
	new FixForm({
		id : id
	}).show();
}

AmCheckForm0.getST = function(st) {
	return st == '0' ? 'WAIT' : st == '2' ? 'ERROR'
			: st == '3' || st == '4' ? 'WARN' : 'OTHER';
}

//审核
AmCheckForm0.check = function(ids) {
	Ext.Ajax.request({
		url : __ctxPath
				+ '/pdaweb/checkPdaAmMeterList.do?fileName='
				+ ids,
		waitMsg : '正在提交数据...',
		timeout: 30000,		
		method : 'post',
		success : function(response) {
			Ext.ux.Toast.msg("操作信息", "审核成功");
			Ext.getCmp('AmCheckForm0Grid').getStore().reload();
		},
		failure : function() {
//			Ext.Msg.alert("操作信息", "审核失败");
			Ext.MessageBox.show({
				title : '操作信息',
				msg : '审核失败',
				buttons : Ext.MessageBox.OK,
				icon : 'ext-mb-error'
			});
		}
	});
}

	
